package com.androturka;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


class FilterAdapter extends BaseAdapter {

	private Filter[] filters;
	private Context mContext;

	public FilterAdapter(Context context, Filter[] filters) {
		mContext = context;
		this.filters = filters;
	}

	@Override
	public int getCount() {
		return this.filters.length;
	}

	@Override
	public Object getItem(int position) {
		return filters[position];
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view;

		view = LayoutInflater.from(mContext).inflate(R.layout.filter_item,
				parent, false);
		
		/*
		TextView filterID = (TextView) view.findViewById(R.id.filterID);
		TextView filterCityID = (TextView) view.findViewById(R.id.filterCityID);
		TextView filterMagnitude = (TextView) view.findViewById(R.id.filterMagnitude);
		TextView filterDistance = (TextView) view.findViewById(R.id.filterDistance);
		*/
		
		TextView filterOzet = (TextView) view.findViewById(R.id.filterOzet);
		String[] cityArray = mContext.getResources().getStringArray(R.array.city_array);
		if ( filters[position] != null ) {
			
			if ( filters[position].cityid == 0 ){
				filterOzet.setText("Bütün Türkiye'de " + Double.toString(filters[position].magnitude) + "'den Şiddetli");
				
			}	
			else {
				filterOzet.setText( cityArray[filters[position].cityid] + " " + Integer.toString(filters[position].distance) + " Km Mesafede " + Double.toString(filters[position].magnitude) + "'den Şiddetli");
			}
			
			/*
			filterID.setText(position);			
			filterCityID.setText(Integer.toString(filters[position].cityid));
			filterMagnitude.setText(Double.toString(filters[position].magnitude));
			filterDistance.setText(Integer.toString(filters[position].distance));			
			*/
		}
		
		return view;
	}


	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}	
}